<?php
namespace app\np\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\Db;
use think\Config;
class Cover extends Command
{
    protected function configure()
    {
        $this->setName('cover')->setDescription('cover every Minutes ');

    }
    protected function execute(Input $input, Output $output)
    {

       //每分钟执行平仓

        $config_day=  Db::name('configs')->where('group_config_id',6)->select();

        $cur =1;
    if(!empty($config_day)){
                foreach($config_day as $k=>$v){
                        if($v['is_position']){
                            $cur = $v['value'];
                            break;
                        }
                }
        }

        //订单流操作
        $OrderDetails= new \app\np\model\OrderDetails;//订单详情 前台订单卖出操作
        $cur = 1;
        $sqlcurDay = "INTERVAL {$cur} DAY";

    $result =   $result = $OrderDetails->where(["is_sell"=>1])->where("unix_timestamp(DATE_ADD(curdate(), INTERVAL 8 HOUR))>=unix_timestamp(DATE_ADD(DATE_ADD(FROM_UNIXTIME(sell_time, '%Y%m%d'),{$sqlcurDay}), INTERVAL 8 HOUR))")->order("sell_time")->paginate(5)->toArray();;
        //   $result = $OrderDetails->where(["is_sell"=>1])->where("unix_timestamp(DATE_ADD(curdate(), INTERVAL 8 HOUR))>=unix_timestamp(DATE_ADD(DATE_ADD(FROM_UNIXTIME(sell_time, '%Y%m%d'),{$sqlcurDay}), INTERVAL 8 HOUR))")->select(false);

        if(isset($result['data'])){
            $data = $result['data'];
            foreach($data as $k=>$v){ //处理符合需求的每个订单
                $OrderDetails->selloutNextDay($cur,$v);

            }
        }
        /*get_m_config($key);
        getOneConfigById()*/
      //  $output->writeln("TestCommand:create table22 sucess");
    }
}